﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;

namespace DataBaseBackUpUtil
{
    public class FLog
    {
        public static void WriteLog(string text)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory;
            path = System.IO.Path.Combine(path
            , "Logs\\");
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }
            string fileFullName = System.IO.Path.Combine(path, string.Format("{0}.txt", "log_" + DateTime.Now.ToString("yyyyMMdd")));
            using (StreamWriter output = System.IO.File.AppendText(fileFullName))
            {
                output.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+":"+text);

                output.Close();
            }

        }

        public static void WriteLog(string filename, string text)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory;
            path = System.IO.Path.Combine(path
            , "Logs\\");
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }
            string fileFullName = System.IO.Path.Combine(path, string.Format("{0}.txt", filename + "_" + DateTime.Now.ToString("yyyyMMdd")));
            using (StreamWriter output = System.IO.File.AppendText(fileFullName))
            {
                output.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":" + text);

                output.Close();
            }

        }

        public static void WriteLog(string dirpath, string filename, string text)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory;
            path = System.IO.Path.Combine(path
            , dirpath + "\\");
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }
            string fileFullName = System.IO.Path.Combine(path, string.Format("{0}.txt", filename + "_" + DateTime.Now.ToString("yyyyMMdd")));
            using (StreamWriter output = System.IO.File.AppendText(fileFullName))
            {
                output.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":" + text);

                output.Close();
            }
        }
    }
}